﻿#ifndef __SS_WSPP_SESSION_H__
#define __SS_WSPP_SESSION_H__
//#include "../../StarSeekerBaseLib/ssBaseDefine.h"
#include "time/ssTime.h"
#include "string/ssString.h"
#include "message/ssNetMsgHead.h"
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/server.hpp>

namespace StarSeeker
{

typedef websocketpp::server<websocketpp::config::asio> server;

class ssWsppBase;

class ssWsppSession
{
	friend class ssWsppNetwork;
	friend class ssWsppClientNetwork;
public:
	ssWsppSession();
	~ssWsppSession();

	//重置
	void Init(u32 id, websocketpp::connection_hdl hdl, boost::asio::ip::tcp::socket* s, ssWsppBase* pNetwork);
	//收包间隔检测 @启用功能 @间隔时间（毫秒）@临界次数
	void SetTimeCheck(bool timeCheck, i64 intervalTime=500, u16 checkCount=20);
	//收数据
	bool32 OnReceive(ssNetMsgHead* head);
	//getip
	const char* GetIp();
	//建立websocket连接
	void OnOpen();
	//连接是否建立
	bool IsConnected();

private:
	//间隔检查
	void OnTimeCheck(u16 fastCount);


	bool							m_timeCheck;	//是否检测收包间隔
	i64								m_intervalTime;	//收包间隔,毫秒
	i64								m_lastTime;		//上次收包时间,毫秒
	u16								m_fastCount;	//频繁次数,超过20次断线
	u16								m_checkCount;	//超过这个次数就触发事件

	bool							m_isConnect;
	u32								m_sessionID;
	boost::asio::ip::tcp::socket*	m_socket;
	ssWsppBase*						m_pNetwork;
	websocketpp::connection_hdl		m_hdl;
	ssString						m_ip;
};

}
#endif
